<?php
include(APP_PATH.'/Lib/Action/AuthAction.class.php');

class ReviewAction extends AuthAction {

	public function abst() {
		if (!isset($_GET['choice']) || !isset($_GET['id'])) {
			$this->error('发生错误！');
			exit;
		}

		$aid = intval($_GET['id']);
		$review = $_GET['choice']=='pass'?1:0;

		$tReview = M('abst_review');
		$ret = $tReview->data(array(
			'aid' => $aid,
			'ans' => $review,
			'mname' => $_SESSION['account'],
			'mtime' => time()
		))->add();

		echo '<div style="padding:30px 60px;text-align:center;">';
		echo $ret?'<h1>保存成功！</h1>':'<h1>噢！保存失败</h1>';
		echo '<p style="color:red;padding-top:2em;">请刷新后查看结果。</p></div>';
	}

	public function advice() {

		$id = intval($_GET['id']);
		$this->assign('id', $id);

		$tblAbstract = M('abstract');
        $abst = $tblAbstract->where("aid={$id}")->find();
        if (empty($abst)) return ;

		$tblMember = M('member');
		$memb = $tblMember->where("uid={$abst['uid']}")->find();
		if (empty($memb)) return ;
		$this->assign('author', $memb['name']);

		$tblAdvice = M('abst_review_advice');
		$advice = $tblAdvice->where("aid={$id}")->find();
		if (empty($advice)) {
			$this->assign('isExsit', 0);
			$this->assign('advice', '');
		} else {
			$this->assign('isExsit', 1);
			$this->assign('advice', $advice['advice']);
			$this->assign('raid', $advice['raid']);
		}


		$this->display();
	}

	public function do_advice() {

		$aid = intval($_POST['aid']);
		$isExsit = $_POST['isExsit'] == '1';

		$tblAdvice = M('abst_review_advice');

		$data = array(
			'mname' => $_SESSION['account'],
			'mtime' => time(),
			'aid' => intval($_POST['aid']),
			'advice' => $_POST['advice']
		);

		if ($isExsit) {
			$data['raid'] = $_POST['raid'];
			$ret = $tblAdvice->save($data);
		} else {
			$ret = $tblAdvice->data($data)->add();
		}
		
		$this->assign('statue', $ret);
		$this->display();
	}





}






